#include <stdio.h>
#include <stdlib.h>

#include "queue.h"

struct LIST_ITEM {
    int value;
    LIST_ENTRY(LIST_ITEM) entry;
};

static LIST_HEAD(,LIST_ITEM) list_head;
//static LIST_HEAD(,LIST_ITEM) list_head = LIST_HEAD_INITIALIZER();

int main(int argc, char *argv[])
{
    int i = 0;
    struct LIST_ITEM *item;
    struct LIST_ITEM *tmp_item;

    LIST_INIT(&list_head);

    if (LIST_EMPTY(&list_head))
        printf("List is empty\n");

    for( i = 0; i < 10; i += 1)
    {
        item = (struct LIST_ITEM *)malloc(sizeof(struct LIST_ITEM));
        item->value = i;
        LIST_INSERT_HEAD(&list_head, item, entry);
    }

    printf("after insert 10 item to list:\n");
    LIST_FOREACH(item, &list_head, entry)
        printf("item value = %d\n", item->value);

    LIST_FOREACH(tmp_item, &list_head, entry)
    {
        if(tmp_item->value % 2 != 0)
            LIST_REMOVE(tmp_item, entry);
    }

    printf("after delete items from list:\n");
    LIST_FOREACH(item, &list_head, entry)
        printf("item value = %d\n", item->value);

    /* item->value = 9, has been removed, so this will dump */
    LIST_REMOVE(tmp_item, entry);

    return 0;
}
